#ifndef _Level_H_
#define _Level_H_

#include "Box2D.h"
#include "wiisprite.h"
#include "portii.h"
#include "portal.h"

#include <vector>

#include "cake.h"

#include "LevelBuilder.h"

#include "pointer.h"

#include "background.h"

#include "portalhud.h"

#include <string.h>

#include "textbubble.h"

#include "soundmanager.h"

#include "storydata.h"

#include "randomjunk.h"

#include "settings.h"

using namespace wsp;

class Level {

	public:
		Level(SoundManager* ptrSndManager, Settings* settingsPtr);
		~Level();
		
		void Init(LevelBuilder* lvl);
				
		bool Update(Pointer* ptr);
		
		void PreRender();
		
		//Return true if we need to wait for a press
		bool Render();
		
		
		void SetTimeStep(float32 t){_timeStep = t;}
		
		void SetStartPosition(float x, float y){_sx = x; _sy = y; _portii->SetLocation(x, y);}

		float GetOffsetX(){return _screenOffsetX;}
		float GetOffsetY(){return _screenOffsetY;}

		b2World* GetWorld(){return _world;}
		
		void Reset();
		
		bool PortalWillStick(Pointer* ptr);
		
		Sprite* GetPortalSprite(Pointer* ptr);
		
		bool Won(){return _won;}
		
		void SetMode(GameMode::Type gm){_mode = gm;}
		GameMode::Type GameMode(){return _mode;}
		
		void RenderSummary(bool highScore);
		void RenderDead();
		
		void SetName(char* name){_lvlName = std::string(name);}
		const char* GetName(){return _lvlName.c_str();}
		int GetTime(){return _hud->GetTimeElapsed();}
		int GetPortalCount(){return _hud->GetPortalsSpawned();}
		
	private:
		
		void CleanUp();
		
		void CheckCakeHits();
		
		bool CheckForDeadPlayer();
		
		Portii* _portii;
		
		Portal* _portalA;
		Portal* _portalB;
		
		b2World* _world;
		
		float32 _timeStep;
		int32 _iterations;

		float _screenOffsetX;
		float _screenOffsetY;

		float _sx;
		float _sy;
		
		bool _doDrawSight;
		float _sightX;
		float _sightY;
		Quad dQ;

		std::vector<Cake*> _cakes;
		std::vector<Quad*> _npZones;
		
		std::vector<Sprite*> _transGround;
		std::vector<Sprite*> _ground;
		
		std::vector<StoryData*> _storyText;
		int _storyIndex;
		TextBubble* _textBubble;
		
		std::string _lvlName;
		
		Background* background;
		
		PortalHud* _hud;
		
		Sprite _fireSprite;
		
		SoundManager* _ptrSndManager;
		
		bool _cinematic;
		
		bool _won;
		bool _dead;
		
		GameMode::Type _mode;
		
		RandomJunk* _randomJunk;
		
		Image* _completeImage;
		Image* _scoreImage;
		Image* _deadImage;

		Image* portal_a_Image;
		Image* portal_b_Image;
		
		Image* open_portal_a_Image;
		Image* open_portal_b_Image;
		
		Image* wall_portal_b_Image;
		Image* wall_portal_a_Image;
		
		Image* sight_a_Image;
		Image* sight_b_Image;
		Image* sight_both_Image;
		Image* sight_none_Image;
		
		Settings* _ptrSettings;
};

#endif //_Level_H_
